<?php
/**
 * Created by PhpStorm.
 * User: 10037
 * Date: 2022/5/31
 * Time: 10:47
 */

namespace app\admin\model;


use think\facade\Request;
use think\Model;

class Business extends Model
{
    protected $pk="id";

    public function addBusiness($data){
       return $this->insertGetId($data);
    }

    public function busClass(){
        return $this->belongsTo(Busclass::class,'businessClassId','id');
    }

    public function sonClass(){
        return $this->belongsTo(Busclass::class,'buSecondClass','id');
    }

    public function selectAllBus($page){

        return $this->with(['busClass','sonClass'])->where('delete','=',0)->page($page,10)->select();
    }

    public function selectAllBusCount(){
        return $this->where('delete','=',0)->count();
    }

    public function selectIdBus($id){
        return $this->where('delete','=',0)->find($id);
    }

    public function deleteBus($id){
        $result= $this->find($id);
        $result['delete']=1;
        return $result->save();
    }
}